home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / graph3D / graph3D source / PICTfile.c < prev    next >
Text File  |  1993-09-17  |  2KB  |  131 lines

  1. /*
  2.     Copyright '89    Christopher Moll
  3.     all etceteras reserved
  4. */
  5.  
  6.  
  7. #include    "graph3D.h"
  8.  
  9. extern    EventRecord        theEvent;
  10. extern    Boolean        grphOnScrn;
  11. extern    WindowPtr        graphWind;
  12.  
  13. Boolean    GetFileID(...);
  14.  
  15.  
  16. SavePICT(useObjects)
  17. Boolean    useObjects;
  18. {
  19.     PicHandle    drawPict;
  20.     char    fileName[100];
  21.     int        volRef, fileRef, err;
  22.     long    byteCount;
  23.     Boolean        GetFileID();
  24.     PicHandle    GetGraphPICT();
  25.  
  26.     if (NOT(GetFileID(fileName, "\PSave PICT:", "", &volRef)))
  27.         return;
  28.     drawPict = GetGraphPICT(useObjects);
  29.  
  30.     if (err = Create(fileName, volRef, 'MDPL', 'PICT'))
  31.         goto Fail;
  32.     if (err = FSOpen(fileName, volRef, &fileRef))
  33.         goto Fail;
  34.     if (err = SetEOF(fileRef, 512L))
  35.         goto Fail;
  36.     if (err = SetFPos(fileRef,fsFromStart, 512L))    /* skip header */
  37.         goto Fail;
  38.  
  39.     HLock(drawPict);
  40.     byteCount = GetHandleSize(drawPict);
  41.     if (err = FSWrite(fileRef, &byteCount, *drawPict))
  42.         goto Fail;
  43.     if (err = FSClose(fileRef))
  44.         goto Fail;
  45.     HUnlock(drawPict);
  46.     KillPicture(drawPict);
  47.     return;
  48.  
  49. Fail:
  50.     sprintf(fileName, "Error saving PICT: %d", err);
  51.     GenralAlert(ctop(fileName));
  52. }
  53.  
  54.  
  55.  
  56. /*** act on any update or activate events pending ***/
  57. AllowUpdat()
  58. {
  59.     if (GetNextEvent(updateMask, &theEvent))    /* ROM */
  60.         DoEvent();
  61.     if (GetNextEvent(updateMask, &theEvent))    /* ROM */
  62.         DoEvent();
  63. }
  64.  
  65.  
  66. PicHandle
  67. GetGraphPICT(useObjects)
  68. Boolean    useObjects;
  69. {
  70.     PicHandle    drawPict;
  71.     Boolean        svGraphSt;
  72.  
  73.     if (useObjects)
  74.     {
  75.         svGraphSt = grphOnScrn;
  76.         grphOnScrn = FALSE;
  77.         drawPict = OpenPicture(&graphWind->portRect);
  78.             DrawGraph();
  79.         ClosePicture();
  80.         grphOnScrn = svGraphSt;
  81.     }
  82.     else
  83.     {
  84.         SelectWindow(graphWind);
  85.         AllowUpdat();
  86.  
  87.         RmvGraphGrow();
  88.         DrawRotHndls();
  89.  
  90.         drawPict = OpenPicture(&graphWind->portRect);
  91.             CopyBits(&graphWind->portBits, &graphWind->portBits,
  92.                         &graphWind->portRect, &graphWind->portRect,
  93.                         srcCopy, NIL);
  94.         ClosePicture();
  95.         PutGraphGrow();
  96.         DrawRotHndls();
  97.     }
  98.     return(drawPict);
  99. }
  100.  
  101. static
  102. RmvGraphGrow()
  103. {
  104.     Rect    iconR;
  105.  
  106.     iconR.top = graphWind->portRect.bottom - 16;
  107.     iconR.left = graphWind->portRect.right - 16;
  108.     iconR.bottom = graphWind->portRect.bottom;
  109.     iconR.right = graphWind->portRect.right;
  110.     EraseRect(&iconR);
  111. }
  112.  
  113. Boolean
  114. GetFileID(newfName, prompt, defName, volRefP)
  115. Uchar    *newfName, *prompt, *defName;    /* pascal strings */
  116. int        *volRefP;
  117. {
  118. static    Point    where = {80, 100};
  119.     SFReply     reply;
  120.  
  121.     SFPutFile(where, prompt, defName, NIL, &reply);
  122.  
  123.     if (reply.good)
  124.     {
  125.         *volRefP = reply.vRefNum;
  126.         Pstrcpy(reply.fName, newfName);
  127.         return(TRUE);
  128.     }
  129.     else
  130.         return(FALSE);
  131. }